<?php
class View_Bug_Manager_Message extends CMF_Krypton_Core_DefinitionView
{
	/**
	 *	Contructs HTML Output.
	 *	@access		public
	 *	@return		string
	 */
	public function buildContentMessage()
	{
		$config		= $this->registry->get( 'config' );
		$request	= $this->registry->get( 'request' );
		$auth		= $this->registry->get( 'auth' );
		$words		= $this->words['bug']['message'];

		if( $bug_id	= $request->get( 'bug_id' ) )
		{
			$bug	= new Bug( $bug_id );
			$bugdata	= $bug->getData( TRUE );
			if( count( $bugdata ) )
			{
				$assign	= new Assignment();
				$assign->focusForeign( "bug_id", $bug_id );
				$assignments	= $assign->getData( false );
				if( count( $assignments ) )
				{
					//  --  LISTENERS  --  //
					$listeners	= array();
					$current	= $auth->getCurrentUser();

					//  --  AUTHOR  --  //
					$author	= new User( $bugdata['author'] );
					$author	= $author->getData( TRUE );
					$listeners[]	= $author['user_id'];

					//  --  DEVELOPERS  --  //
					$assign	= new Assignment();
					$assign->focusForeign( "bug_id", $bug_id );
					$devs	= $assign->getData( false );
					foreach( $devs as $dev )
						$listeners[] = $dev['user_id'];

					//  --  RECEIVERS  --  //
					$opt_receivers	= array();
					foreach( $listeners as $listener )
					{
						if( $current != $listener )
						{
							$listener	= new User( $listener );
							$listener	= $listener->getData( TRUE );
							$opt_receivers[$listener['user_id']]	=  $listener['username'];
						}
					}

					$sources	= array(
						'opt_receivers'		=> $opt_receivers,
						);

					$ui	= $this->buildForm( 'bug', 'sendMessage', 'bug', 'message', array(), $sources );

					$input_medium	= $this->html->Radio( 'medium', '1', '1' );
					$button_send		= $this->html->Button( 'sendMessage', $words['button'] );
					$ui['label_medium']		= $this->html->Label( '', "Medium" );
					$ui['field_medium']		= $this->html->Field( '', $input_medium );
					$ui['field_button']		= $this->html->Field( '', $button_send );

					$ui['form']		= $this->html->Form( 'sendMessage', "?link=".$request->get( 'link' )."&bug_id=".$request->get( 'bug_id' ) );
					$ui['colgroup']		= $this->html->ColumnGroup( "30%", "70%" );
					$ui['caption']		= $this->html->TableCaption( $words['caption'] );
					$ui['heading']		= $words['heading'];

					return $this->loadTemplate( 'bug.message', $ui );
				}
			}
			else
				$this->messenger->noteError( "Bug is not existing." );
		}
		else
			$this->messenger->noteError( $this->words['bug']['msg']['error1'] );
	}
}
?>